{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 读取数据并预览数据分布"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## pandas读取数据集并划分训练/测试集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "source_data=pd.read_excel('Test_Train_Set.xlsx')\n",
    "source_data=np.array(source_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train=source_data[:,1:3]\n",
    "y_train=source_data[:,0]\n",
    "x_test=source_data[:,4:]\n",
    "y_test=source_data[:,3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## plt绘图，预览训练集分布效果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x7fcf9e95a700>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAWQUlEQVR4nO3da4xcZ33H8e/PjhyUckvwFlLf1kGOqFtQ0o5cqbxIuDupZKeAqN2NlJSA24ApEiDhaBFCriIKvdAXNRc3SoE0YIIr2kUEWSGXF60S6rFIQh3LyWJsbJOS5RKqKiLG8b8vztn4ZDy7c7x7Zs6cZ34fabVzznlm5p/j2V+eOZfnUURgZmbNt6TuAszMrBoOdDOzRDjQzcwS4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z0U9l631H/m+8V9Kq83xuVUq/X34Yay1wX2H1oPftvNKYsWgOkr4DvKrLpsniQkSEpDmv35R0KfBaYF9h9S1kYbWM7PrUjwI7h6DeNRFxUtJlwH2Svk8WRJWqeN/eAdwQEWfy1ZXv21Eh6XqgBVxVWH3OZyIiftD9FQbmm8BXI+JZSX9O9k3ojTXX1MsWYG9EPFdYN1T7NulAj4g3z7VN0k8kXRoRT+ah8tQ8L/Uu4BsR8evCa8/2QJ+V9M/AR4ah3og4mf8+IukB4ErgX4GXS7og72muBE7WXauklwLfAiYj4qHCa1e+b7s4CawqLHfbJ7NtTki6AHgZ8LOSz61SqfeT9Gay/6FeFRHPzq6f4zPRz9DpWW9E/KyweBvZeZfZ517d8dwHKq/wrPP5t9wCvL+4ooZ9O69RPuQyBcyeQb8B+Pd52p5z3CwPqtnj09cB/119iS/Qs15JF88enpC0HHg98FhkZ2/uJzsPMOfzB1zrMuAbwJcjYm/HtkHs2/3AOmVX/ywj+2PtvEqh+N/xTuC+fF9OAVvyq2DWAuuA/+pDjaVrlXQl8AVgU0Q8VVjf9TPRx1rL1ntpYXETcCh/vA94a173xcBbeeE344HXmtf7GrKTtA8W1tWxb+dX91nZun7IjoXeCzwBfAe4JF/fAm4rtBsn+z/2ko7n3wd8nyxs/gV4cd31An+Y1/RI/vumwvMvIwudaeDrwIU113o98Gvg4cLPFYPct8C1wONkParJfN1OslAEeFG+r6bzfXdZ4bmT+fMOA9cM4PPaq9bvAD8p7MupXp+Jmuv9JHAwr+t+4DWF57473+fTwJ/VXWu+/AngrzueV8u+ne/Ht/6bmSVilA+5mJklxYFuZpYIB7qZWSIc6GZmiXCgm5klwoFuZpYIB7qZWSL+H4JbqjDSLkieAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "plt.scatter(x_train[y_train==1,0],x_train[y_train==1,1],c='b')\n",
    "plt.scatter(x_train[y_train==0,0],x_train[y_train==0,1],c='r')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 构建线性模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## sigmoid函数 前向推导计算函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def sigmoid(x):\n",
    "    return 1/(1+np.exp(-x))\n",
    "def forward(w,b,x):\n",
    "    return sigmoid(np.dot(x,w)+b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Loss函数，优化方向为极大值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def loss(y_pre,label):\n",
    "    return np.dot(label,y_pre)+np.dot((1-label),(1-y_pre))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 反向传播，梯度上升更新参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def update(w,b,x,label,lr):\n",
    "    y_pred=forward(w,b,x)\n",
    "    cost=loss(y_pred,label)\n",
    "    z=np.dot(x,w)+b\n",
    "    delta_w=np.matmul((label-sigmoid(z)),x)\n",
    "    delta_b=np.sum(label-sigmoid(z))\n",
    "    w=w+lr*delta_w\n",
    "    b=b+lr*delta_b\n",
    "#     print('loss:',cost)\n",
    "#     print(delta_w)\n",
    "#     print(delta_b)\n",
    "    return w,b,cost"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 计算准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "def acc(w,b,x,label):\n",
    "    y_pred=np.round(forward(w,b,x))\n",
    "    return np.sum(y_pred==label)/len(label)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 训练模型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 设置最小迭代次数10，学习率0.1，更新直至两次更新权重差小于errm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "iter: 0 loss: 15.941527629058264\n",
      "iter: 50 loss: 22.396001173569687\n",
      "iter: 100 loss: 23.764127736437263\n",
      "iter: 150 loss: 24.391949689214783\n",
      "iter: 200 loss: 24.759754039990966\n",
      "iter: 250 loss: 25.00413636606001\n",
      "iter: 300 loss: 25.17933706725741\n",
      "iter: 350 loss: 25.31148247193685\n",
      "iter: 400 loss: 25.414837232593158\n",
      "iter: 450 loss: 25.49790555647442\n",
      "iter: 500 loss: 25.56609872609782\n",
      "iter: 550 loss: 25.62303733395983\n",
      "iter: 600 loss: 25.67124250758418\n",
      "iter: 650 loss: 25.712527765560417\n",
      "iter: 700 loss: 25.748233286610205\n",
      "iter: 750 loss: 25.779372244675677\n",
      "iter: 800 loss: 25.80672564459683\n",
      "iter: 850 loss: 25.83090574034243\n",
      "iter: 900 loss: 25.852399606065333\n",
      "iter: 950 loss: 25.871599784703562\n",
      "iter: 1000 loss: 25.888826297695033\n",
      "iter: 1050 loss: 25.904342743430156\n",
      "iter: 1100 loss: 25.918368266333623\n",
      "iter: 1150 loss: 25.9310865874849\n",
      "iter: 1200 loss: 25.94265290914376\n",
      "iter: 1250 loss: 25.953199257632065\n",
      "iter: 1300 loss: 25.962838663369613\n",
      "iter: 1350 loss: 25.971668464140393\n",
      "iter: 1400 loss: 25.979772939677744\n",
      "iter: 1450 loss: 25.98722543087336\n",
      "iter: 1500 loss: 25.994090057889814\n",
      "iter: 1550 loss: 26.000423123295764\n",
      "iter: 1600 loss: 26.006274265778238\n",
      "iter: 1650 loss: 26.01168741480173\n",
      "iter: 1700 loss: 26.016701585255614\n",
      "iter: 1750 loss: 26.02135154259777\n",
      "iter: 1800 loss: 26.025668362517344\n",
      "iter: 1850 loss: 26.029679904168066\n",
      "iter: 1900 loss: 26.033411212183275\n",
      "iter: 1950 loss: 26.036884859694652\n",
      "iter: 2000 loss: 26.04012124223362\n",
      "iter: 2050 loss: 26.0431388305459\n",
      "iter: 2100 loss: 26.045954388881754\n",
      "iter: 2150 loss: 26.04858316415237\n"
     ]
    }
   ],
   "source": [
    "m_w=np.random.random(x_train.shape[1])\n",
    "m_b=0\n",
    "err=1e-3\n",
    "iter_num=0\n",
    "min_idx=10\n",
    "w_back=m_w\n",
    "b_back=m_b\n",
    "while iter_num<min_idx or (np.sum(np.abs(w_back-m_w))+np.abs(b_back-m_b))>err:\n",
    "    w_back=m_w\n",
    "    b_back=m_b\n",
    "    m_w,m_b,cost=update(m_w,m_b,x_train,y_train,0.1)\n",
    "    if iter_num%50==0:\n",
    "        print('iter:',iter_num,'loss:',cost)\n",
    "        #print(acc(m_w,m_b,x_test,y_test))\n",
    "    iter_num+=1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 输出权重w和偏移b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "直线参数:\n",
      " w: [ 2.53715482 19.99529099] \n",
      " b: -8.708147054361877\n"
     ]
    }
   ],
   "source": [
    "print('直线参数:\\n','w:',m_w,'\\n b:',m_b)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 绘图，显示直线划分效果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<matplotlib.lines.Line2D at 0x7fcf9e9c6910>]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EA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X8DfMfdL5nZ7xH8JXRnzDEVsgl43N2vRfZV1blNdUJ3949OdszMTpnZUncfCZPK6Sle6jeB77v7lchrZ3qgl8zsvwJfrIZ43f1E+P2ImT0N3Ab8FbDAzBrCnuZy4ETcsZpZO/BDYJu7PxN57ZKf2zxOACsi2/nOSabNsJk1APOB14p8bikV9X5m9lGCX6h3uPulzP5JPhPlTDoF43X31yKbjxBcd8k890M5z3265BGOm87/5Sbg96M7Yji3U6rlIZc9QOYK+n3AD6Zoe924WZioMuPTnwT+X+lDnKBgvGa2MDM8YWYdwAeBAx5cvXmK4DrApM+vcKyNwPeBv3T3x3OOVeLc7gPWWDD7p5HghzV3lkL033Ev8GR4LvcAm8JZMKuBNcDPyxBj0bGa2W3AXwD3uPvpyP68n4kyxlpsvEsjm/cAB8PHe4GPh3EvBD7OxL+MKx5rGG8vwUXan0X2xXFupxb3Vdm4vgjGQp8AXgJ+AiwK9/cBj0Ta9RD8xq7Lef6TwC8Iks1/A1rjjhe4PYzphfD7ZyLPv4Eg6QwB3wOaYo7108AV4PnI162VPLfA3cBhgh7VtnDfdoKkCDA3PFdD4bm7IfLcbeHzBoG7KvB5LRTrT4BTkXO5p9BnIuZ4vwzsD+N6CuiNPPe3w3M+BPzzuGMNtx8CvpLzvFjO7VRfuvVfRCQlannIRUQkVZTQRURSQgldRCQllNBFRFJCCV1EJCWU0EVEUkIJXUQkJf4/zzSVXcPYhnoAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x_train[y_train==1,0],x_train[y_train==1,1],c='b')\n",
    "plt.scatter(x_train[y_train==0,0],x_train[y_train==0,1],c='r')\n",
    "xx=np.arange(-0.75,0.75,0.01)\n",
    "yy=-m_w[0]/m_w[1]*xx-m_b/m_w[1]\n",
    "plt.plot(xx,yy)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 计算准确率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练集准确率ACC: 0.8666666666666667\n",
      "测试集准确率ACC: 0.7333333333333333\n"
     ]
    }
   ],
   "source": [
    "print('训练集准确率ACC:',acc(m_w,m_b,x_train,y_train))\n",
    "print('测试集准确率ACC:',acc(m_w,m_b,x_test,y_test))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "218.08424377441406px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
